<!DOCTYPE html>
<html>
<head>
<title>资源互助区 - {config[webname]} - {config[webtitle]}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="{config[keyword]}">
<script type="text/javascript" src="js/jquery-ui-1.8.16/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/common.js"></script>

<script type="text/javascript" src="js/PublishTool.js"></script>
<script type="text/javascript" src="js/shortcut.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.8.16/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" href="styles/common.css" />
<link rel="stylesheet" type="text/css" href="styles/table.css" />
<script type="text/javascript">
var publishTool = new PublishTool();
$(document).ready(function(){
	$("#links").tabs();
	$("#lxset").buttonset();
	$("#lx_torrent").click();
	
	<!--if($show_post)-->
	$("#show").openDialog("资源");
	shortcut.add("Esc",function(){
		$("#show").closeDialog();
	});
	<!-- end -->
});
function v_email(email){
	var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
	return pattern.test(email);
};
function qiu_show(){
	
	$res = $("#qp").openDialog({title:"发布一个资源请求"});
	
	$("#zymc").focus();
	shortcut.add("Esc",function(){$("#qp").closeDialog();});
}
function qiu_ok(){
	var zymc = $("#zymc").val().trim();
	var zysm = $("#zysm").val().trim();
	var tzyx = $("#tzyx").val().trim();

	if(zymc.length==0){
		alert("请填写资源名称");
		$("#zymc").focus();
		return false;
	}
	if(tzyx.length>0){
		if(!v_email($("#tzyx").val().trim())){
			alert("邮箱格式不正确，请检查");
			$("#tzyx").focus();
			return false;
		}
	}
	$("#loading").text("发布中。。。").openDialog({showHeader:false});
	
	$.post("qiu.php",{qiu:"1",zymc:zymc,zysm:zysm,tzyx:tzyx},function(data){
		if(data==1){
			qiu_cancel();
			window.location.href="qiu.php";
		}else{
			alert("发布失败，请稍后再试！");
		}
	});
}

function qiu_cancel(){
	$("#qp").closeDialog();
	$("#zymc").val("");
	$("#zysm").val("");
	$("#tzyx").val("");
}

function lx_setted(lx){
	if(lx=="torrent"){
		$(".div_torrent").css("display","");
		$(".div_ed2k").css("display","none");
		$(".div_magnet").css("display","none");
		$(".div_thunder").css("display","none");
		$("#input_torrent").focus();
	}else if(lx=="ed2k"){
		$(".div_torrent").css("display","none");
		$(".div_ed2k").css("display","");
		$(".div_magnet").css("display","none");
		$(".div_thunder").css("display","none");
		$("#input_ed2k").focus();
	}else if(lx=="magnet"){
		$(".div_torrent").css("display","none");
		$(".div_ed2k").css("display","none");
		$(".div_magnet").css("display","");
		$(".div_thunder").css("display","none");
		$("#input_magnet").focus();
	}else if(lx=="thunder"){
		$(".div_torrent").css("display","none");
		$(".div_ed2k").css("display","none");
		$(".div_magnet").css("display","none");
		$(".div_thunder").css("display","");
		$("#input_thunder").focus();
	}
}
function torrent_setted(fileobj){
	var filepath = fileobj.value.trim();
	
	if(!filepath)return;
	
	if(!publishTool.isTorrentFile(filepath)){
		alert("请选择torrent文件！");
		fileobj.value=null;
		$("#fname_torrent").val("");
		return;
	}
	$("#fname_torrent").val(publishTool.getNameFromTorrentFile(filepath));
}
function ed2k_setted(linkobj){
	var link = linkobj.value.trim();
	
	if(!linkobj.value)return;
	
	var link = linkobj.value;
	if(!publishTool.isEd2kLink(link)){
		alert("ED2K链接格式不正确！");
		linkobj.value="";
		$(linkobj).focus();
		$("#fname_ed2k").val("");
		return;
	}

	$("#fname_ed2k").val(publishTool.getNameFromEd2kLink(link));
}
function magnet_setted(linkobj){
	var link = linkobj.value.trim();
	
	if(!linkobj.value)return;
	
	var link = linkobj.value;
	if(!publishTool.isMagnetLink(link)){
		alert("磁力链接格式不正确！");
		linkobj.value="";
		$(linkobj).focus();
		$("#fname_magnet").val("");
		return;
	}

	$("#fname_magnet").val(publishTool.getNameFromMagnetLink(link));
}
function thunder_setted(linkobj){
	if(linkobj.value==""){
		return;
	}
	var link = linkobj.value;
	if(!publishTool.isThunderLink(link)){
		alert("迅雷链接格式不正确，必须以thunder://开头！");
		linkobj.value="";
		$(linkobj).focus();
		return;
	}
}
function addlink_show(id){
	$("#addlink").openDialog({"title":"提供此资源"});
	$("#link").focus();
	$("#qiu_id").val(id);
	$("#asktitle").text($("#title_"+id).text());
	var lx = $("input[name='lx']:checked").val();
	lx_setted(lx);
	shortcut.add("Esc",function(){$("#addlink").closeDialog();});
}
function addlink_ok(){
	var lx = $("input[name='lx']:checked").val();
	if(lx=="torrent" && $("#input_torrent").val().trim().length==0){
		alert("请选择torrent文件");
		return false;
	}
	if(lx=="ed2k" && $("#input_ed2k").val().trim().length==0){
		alert("请输入ED2K下载地址");
		$("#input_ed2k").focus();
		return false;
	}
	if(lx=="magnet" && $("#input_magnet").val().trim().length==0){
		alert("请输入磁力下载地址");
		$("#input_magnet").focus();
		return false;
	}
	if(lx=="thunder" && $("#input_thunder").val().trim().length==0){
		alert("请输入迅雷下载地址");
		$("#input_thunder").focus();
		return false;
	}
	
	var mail = $("#mail").val().trim();
	if(mail.length>0 && !v_email(mail)){
		alert("邮箱地址不正确");
		$("#mail").select();
		return false;
	}
	$("#loading").text("发布中。。。").openDialog({showHeader:false});
	myform.submit();
}
function addlink_cancel(){
	$dialog.closeDialog();
	$("#addlink input,#addlink textarea").val("");
	return false;
}
</script>
<style>
#qiu{
	position:absolute;
}
.f1{
	width:600px;
}
.f1 label{
	width:60px;
}
.f1_hint{
	margin-left:70px;
}
.f1_field input,.f1_field textarea{
	width:500px;
}
.f1_field textarea{
	overflow-y:visible;
}
#post{
	background-color:#fff;
	padding:5px 20px;
}
.header{
	padding:10px 0px;
	border-bottom: 2px solid #6FBCEA;
}
.post-item{
	margin:20px 0px;
	background-color:#F7F7F7;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
	color:#444;
	padding:10px 20px;
}
.ask{
	padding-bottom:10px;
	border-bottom:1px solid #E0E0E0;
}
.answer{
}
.answer input,label{
	line-height:24px;
}
.answer ul{
	margin-left:5px;
	color:#444;
}
.answer li{
	margin-top:5px;
	margin-left:20px;
	display:list-item;
	list-style-type:square;
	border:1px solid #efefef;
	line-height:24px;
	font-size:12px;
	padding:2px;
	background-color:#FDFFD2;
}
.answer li a{
	color:#444;
}
.answer img{
	width:15px;
	height:15px;
	vertical-align:middle;
	margin-right:2px;
}
#addlink label{
	width:80px;
}
#addlink input{
}
#links textarea{
	width:498px;
	height:58px;
}
#lxset input,#lxset label{
	width:auto;
	text-align:left;
}
#show{
	display:none;
}
</style>
</head>
<body class="div2-body">
<!--#include file="header.html"-->

<div id="post">
	<div class="header">
	<button class="btn" id="btn_qp" onclick="qiu_show()">发布一个资源请求</button>
	</div>
<!-- $posts as $post -->
	<div class="post-item" id="<!-- if($post[show]) -->show<!-- else -->item_{post[id]}<!-- end -->">
		<div class="ask">
			<p>
				<span style="font-size:24px;line-height:30px;font-weight:bold;color:#3A6FE1;" id="title_{post[id]}">{post[zymc]}</span>
				<a href="javascript:addlink_show('{post[id]}')" id="btn_addlink" style="font-size:18px;padding:5px;color:green">提供此资源</a>
			</p>
			<p style="color:#666;font-size:14px;margin-left:10px;">{post[zysm]}</p>
		</div>
		<div class="answer">
		<!-- if($post[replys]) -->
			<ul>
			<!-- $post[replys] as $reply -->
				<li>
				<!-- if($reply[lx]=="torrent") --><img src="{config[weburl]}/resource/res_torrent_20.png"/><!-- end -->
				<!-- if($reply[lx]=="ed2k") --><img src="{config[weburl]}/resource/res_ed2k_20.png"/><!-- end -->
				<!-- if($reply[lx]=="magnet") --><img src="{config[weburl]}/resource/res_magnet_20.png"/><!-- end -->
				<!-- if($reply[lx]=="thunder") --><img src="{config[weburl]}/resource/res_thunder_20.png"/><!-- end -->
				
				<a href="qiu.php?downloadReply={reply[id]}" target="_blank"><!-- if($reply[fname]) -->{reply[fname]}<!-- else -->点击下载<!-- end --></a>
				<span style="color:gray;margin-left:3px;">(
				<!-- if($reply[fsize]) -->{run:}echo $func->cal_size($reply[fsize]);{/run}&nbsp;&nbsp;<!-- end -->
				{reply[download]}次下载
				)</span>
				<!-- if($reply[ly]) -->
				<span style="color:gray;margin-left:10px;">留言：{reply[ly]}</span>
				<!-- end -->
				&nbsp;&nbsp;<small style="font-size:10px;color:#afafaf">{run:}echo $func->calc_publish_time($func->date_int_to_string($reply[publish_time]));{/run}</small>
				</li>
			<!-- end -->
			</ul>
		<!-- else -->
		<p style="color:gray">暂时还没有人提供资源</p>
		<!-- end -->
		</div>
	</div>
<!-- end -->
<div class="digg">{pagenav}</div>
</div>
<!--#include file="footer.html"-->

<div id="qp" class="f1" style="display:none">
	<div class="f1_body">
		<div class="f1_row">
			<label>资源名称</label>
			<span class="f1_field"><input maxlength="200" id="zymc" name="zymc"></span>
			<span class="f1_hint">输入你要找的资源的名称</span>
		</div>
		<div class="f1_row">
			<label style="vertical-align:top">说明</label>
			<span class="f1_field"><textarea maxlength="1000" id="zysm" name="zysm"></textarea></span>
			<span class="f1_hint">详细说明需要的资源内容</span>
		</div>
		<div class="f1_row">
			<label>通知邮箱</label>
			<span class="f1_field"><input id="tzyx" name="tzyx"></span>
			<span class="f1_hint">有人帮你找到资源，系统会发送邮件通知</span>
		</div>
		<div class="f1_row">
			<label></label>
			<span class="f1_btn"><button id="ok" class="btn" onclick="qiu_ok();">发布</button>&nbsp;&nbsp;<button onclick="qiu_cancel();" id="cancel" class="btn_n">取消</button></span>
		</div>
	</div>
</div>
<div id="addlink" class="f1" style="display:none">
	<div class="f1_body">
	<form action="qiu.php?page={page}" enctype="multipart/form-data" method="post" id="myform" name="myform">
		<input type="hidden" id="qiu_id" name="qiu_id" value="">
		<input type="hidden" name="goto" value="{run:}echo urlencode($_SERVER[REQUEST_URI]);{/run}">
		<p id="asktitle" style="font-size:18px;color:#3A6FE1;font-weight:bold;padding:5px;"></p>
		<div class="f1_row">
			<label>资源类型</label>
			<span class="f1_field" id="lxset">
				<input type="radio" id="lx_torrent" name="lx" checked="checked" value="torrent" onclick="lx_setted('torrent');"/><label for="lx_torrent">BT种子</label>
				<input type="radio" id="lx_ed2k" name="lx" value="ed2k" onclick="lx_setted('ed2k');"/><label for="lx_ed2k">ED2K链接</label>
				<input type="radio" id="lx_magnet" name="lx" value="magnet" onclick="lx_setted('magnet');"/><label for="lx_magnet">磁力链接</label>
				<input type="radio" id="lx_thunder" name="lx" value="thunder" onclick="lx_setted('thunder');"/><label for="lx_thunder">迅雷链接</label>
			</span>
		</div>
		<div class="f1_row div_torrent">
			<label>选择BT种子</label>
			<span class="f1_field"><input style="width:400px" id="input_torrent" type="file" name="torrent" title="支持.torrent文件" onchange="torrent_setted(this)"></span>
		</div>
		<div class="f1_row div_ed2k">
			<label style="vertical-align:top">ED2K链接</label>
			<span class="f1_field"><textarea style="width:400px" id="input_ed2k" name="ed2k" maxlength="5000" onchange="ed2k_setted(this)"></textarea></span>
		</div>
		<div class="f1_row div_magnet">
			<label style="vertical-align:top">磁力链接</label>
			<span class="f1_field"><textarea style="width:400px" id="input_magnet" name="magnet" maxlength="5000" onchange="magnet_setted(this)"></textarea></span>
		</div>
		<div class="f1_row div_thunder">
			<label style="vertical-align:top">迅雷链接</label>
			<span class="f1_field"><textarea style="width:400px" id="input_thunder" name="thunder" maxlength="5000" onchange="thunder_setted(this)"></textarea></span>
		</div>
		<div class="f1_row div_torrent">
			<label>资源名</label>
			<span class="f1_field"><input id="fname_torrent" name="fname_torrent" style="width:400px"></span>
		</div>
		<div class="f1_row div_ed2k">
			<label>资源名</label>
			<span class="f1_field"><input id="fname_ed2k" name="fname_ed2k" style="width:400px"></span>
		</div>
		<div class="f1_row div_magnet">
			<label>资源名</label>
			<span class="f1_field"><input id="fname_magnet" name="fname_magnet" style="width:400px" maxlength="200"></span>
		</div>
		<div class="f1_row div_thunder">
			<label>资源名</label>
			<span class="f1_field"><input id="fname_thunder" name="fname_thunder" style="width:400px"></span>
		</div>
		<div class="f1_row">
			<label>留言</label>
			<span class="f1_field"><input id="ly" name="ly" style="width:400px;" maxlength="200"></span>
		</div>
		<div class="f1_row">
			<label>联系邮箱</label>
			<span class="f1_field"><input id="mail" name="mail" style="width:400px;" maxlength="100"></span>
		</div>
		<div class="f1_row">
			<label></label>
			<span class="f1_btn"><button class="btn" onclick="addlink_ok();return false;">添加</button>&nbsp;&nbsp;<button class="btn_n" onclick="addlink_cancel();return false;">取消</button></span>
		</div>
	</form>
	</div>
</div>
<div id="loading" style="display:none;padding:20px;"></div>
</body>
</html>